﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.DALFactory;
namespace KPIS.GERP.GHRMS.BLL
{
    public class RetirementBLL : IRetirementBLL
    {
        private static readonly IRetirementDAL DAL = DataAccess.CreateRetirements();

        private RetirementInfo Info = new RetirementInfo();
        private EmployeeTypeInfo etInfo = new EmployeeTypeInfo();
        private JobSiteInfo jsInfo = new JobSiteInfo();

        public DataSet LoadRetirements(Nullable<int> Sequence, Nullable<int> EmployeeType)
        {
            RetirementInfo info = new RetirementInfo();
            EmployeeTypeInfo etInfo = new EmployeeTypeInfo();
            info.Sequence = Sequence.HasValue ? (int)Sequence : 0;
            if (EmployeeType.HasValue)
                etInfo.Sequence = (int)EmployeeType;

            Info.EmployeeType = etInfo;
            return DAL.LoadRetirements(Info);
        }

        public void Insert(string EmployeeTypes, int BGYear, Nullable<DateTime> StartDate, string JobSite
                , string RefNo, string Title, string Description, string ApprovedName, string ApprovedPosition
                , Nullable<DateTime> ApprovedDate, string Status, string Remarks, int CreatedBy)
        {
            if (EmployeeTypes.Length > 0)
                etInfo.Sequence = Int32.Parse(EmployeeTypes);
            if (JobSite.Length > 0)
                jsInfo.Sequence = Int32.Parse(JobSite);
            
            try
            {
                DAL.Insert(new RetirementInfo(0, etInfo, BGYear, StartDate, jsInfo, RefNo, Title, Description
                    , ApprovedDate, ApprovedName, ApprovedPosition
                    , new MasRecordStatusInfo(Status)
                    , Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string EmployeeTypes, int BGYear, Nullable<DateTime> StartDate, string JobSite
                , string RefNo, string Title, string Description, string ApprovedName, string ApprovedPosition
                , Nullable<DateTime> ApprovedDate, string Status, string Remarks, int UpdatedBy)
        {
            if (EmployeeTypes.Length > 0)
                etInfo.Sequence = Int32.Parse(EmployeeTypes);
            if (JobSite.Length > 0)
                jsInfo.Sequence = Int32.Parse(JobSite);

            try
            {
                DAL.Update(new RetirementInfo(Sequence, etInfo, BGYear, StartDate, jsInfo, RefNo, Title, Description
                    , ApprovedDate, ApprovedName, ApprovedPosition
                    , new MasRecordStatusInfo(Status)
                    , Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
